home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / laptop-mode-tools / modules / configuration-file-control < prev    next >
Text File  |  2009-10-06  |  4KB  |  114 lines

  1. #! /bin/sh
  2. #
  3. # Laptop mode tools module: switch config files based on power state.
  4. #
  5.  
  6. if [ x$CONTROL_CONFIG_FILES = x1 ] ; then
  7.     echo "Swapping out configuration files." >> $OUTPUT
  8.     for CONFFILE in $CONFIG_FILES ; do
  9.         if [ -e $CONFFILE ] ; then
  10.             #
  11.             # Initialize the -nolm-ac, -lm-ac and -batt files if they don't
  12.             # already exist.
  13.             #
  14.             if [ ! -e "$CONFFILE-nolm-ac" ] ; then
  15.                 cp $CONFFILE $CONFFILE-nolm-ac
  16.             fi
  17.             if [ ! -e "$CONFFILE-lm-ac" ] ; then
  18.                 cp $CONFFILE $CONFFILE-lm-ac
  19.             fi
  20.             if [ ! -e "$CONFFILE-batt" ] ; then
  21.                 cp $CONFFILE $CONFFILE-batt
  22.             fi
  23.  
  24.             #
  25.             # Create the .lmbackup file
  26.             #
  27.             if [ "`readlink -f $CONFFILE`" != "$CONFFILE" ] ; then
  28.                 echo "$CONFFILE is a symlink." >> $OUTPUT
  29.                 if [ ! -f "$CONFFILE.lmbackup" ] ; then
  30.                     echo "But there is no $CONFFILE.lmbackup." >> $OUTPUT
  31.                     echo "Creating it now from $CONFFILE-nolm-ac." >> $OUTPUT
  32.                     cp "$CONFFILE-nolm-ac" "$CONFFILE.lmbackup"
  33.                 fi
  34.             else
  35.                 echo "$CONFFILE is not a symlink." >> $OUTPUT
  36.                 if [ "$STATE" = "enabled" ] ; then
  37.                     echo "Saving it to $CONFFILE.lmbackup." >> $OUTPUT
  38.                     cp --backup=numbered "$CONFFILE" "$CONFFILE.lmbackup"
  39.                 fi
  40.             fi
  41.  
  42.             #
  43.             # Swizzle the config file
  44.             #
  45.             if [ "$STATE" != "enabled" ] ; then
  46.                 echo "Laptop mode is not enabled. Restoring $CONFFILE." >> $OUTPUT
  47.                 if [ -f "$CONFFILE.lmbackup" ] ; then
  48.                     mv "$CONFFILE.lmbackup" "$CONFFILE"
  49.                 elif [ "`readlink -f $CONFFILE`" != "$CONFFILE" ] ; then
  50.                     echo "ERROR: $CONFFILE is a symlink but $CONFFILE.lmbackup is not present."
  51.                 fi
  52.             elif [ $ON_AC -eq 1 ] ; then
  53.                 if [ "$ACTIVATE" -eq 1 ] ; then
  54.                     echo "Pointing config file $CONFFILE to $CONFFILE-lm-ac." >> $OUTPUT
  55.                     ln -fs "$CONFFILE-lm-ac" "$CONFFILE"
  56.                 else
  57.                     echo "Pointing config file $CONFFILE to $CONFFILE-nolm-ac." >> $OUTPUT
  58.                     ln -fs "$CONFFILE-nolm-ac" "$CONFFILE"
  59.                 fi
  60.             else
  61.                 echo "Pointing config file $CONFFILE to $CONFFILE-batt." >> $OUTPUT
  62.                 ln -fs "$CONFFILE-batt" "$CONFFILE"
  63.             fi
  64.         fi
  65.     done
  66.     # Notify daemons of configuration change.
  67.     for PROGRAM in $CONFIG_FILE_SIGNAL_PROGRAMS ; do    
  68.         $LM_VERBOSE && echo "Sending SIGHUP to all $PROGRAM processes." >> $OUTPUT
  69.         killall -q -HUP $PROGRAM
  70.     done
  71.  
  72.  
  73.     if [ ! -z "$CONFIG_FILE_RELOAD_SERVICES" ] ; then
  74.         # Determine how we can start/restart services.
  75.         if ( which invoke-rc.d > /dev/null ) ; then
  76.             # Debian uses invoke-rc.d
  77.             RCPROG="invoke-rc.d "
  78.             INITSCRIPT=laptop-mode
  79.         elif ( which service > /dev/null ) ; then
  80.             # RedHat uses service
  81.             RCPROG="service "
  82.             INITSCRIPT=laptop-mode
  83.         else
  84.             # Any other -- we start the init script it ourselves.
  85.  
  86.             # Try non-link directories first, then try links. This helps if one of
  87.             # the locations is linked to another, which is the case on some distros.
  88.             if [ -d /etc/rc.d/init.d -a ! -L /etc/rc.d/init.d ] ; then
  89.                 INIT_D=/etc/rc.d/init.d
  90.             elif [ -d /etc/rc.d -a ! -L /etc/rc.d -a ! -d /etc/rc.d/init.d ] ; then
  91.                 INIT_D=/etc/rc.d
  92.             elif [ -d /etc/init.d -a ! -L /etc/init.d ] ; then
  93.                 INIT_D=/etc/init.d
  94.             elif [ -d /etc/rc.d/init.d ] ; then
  95.                 INIT_D=/etc/rc.d/init.d
  96.             elif [ -d /etc/rc.d ] ; then
  97.                 INIT_D=/etc/rc.d
  98.             elif [ -d /etc/init.d ] ; then
  99.                 INIT_D=/etc/init.d
  100.             else
  101.                 $LM_VERBOSE && echo "Cannot determine location of init scripts." >> $OUTPUT
  102.                 exit 1
  103.             fi
  104.  
  105.             RCPROG="$INIT_D/"
  106.         fi
  107.  
  108.         for SERVICE in $CONFIG_FILE_RELOAD_SERVICES ; do
  109.             $LM_VERBOSE && echo "Reloading service $SERVICE." >> $OUTPUT
  110.             $RCPROG$SERVICE reload
  111.         done
  112.     fi
  113. fi
  114.